package cn.edu.lzzy.entities;



import com.fasterxml.jackson.annotation.JsonBackReference;
import com.mysql.cj.x.protobuf.MysqlxExpr;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;


/**
 * 用户业务实体
 */
@Entity
public class User extends BasicEntity{

    @Transient
    public static final int TYPE_ADMIN=0;
    @Transient
    public static final int TYPE_TEACHER=1;//老师
    @Transient
    public static final int TYPE_STUDENT=2;//学生
    @Transient
    public static final int TYPE_BANNED=-1;//禁用用户
    @Transient
    public static final int COUNT_TYPE=3;

    private String nickName;//昵称
    private String userName;//账号
    private String email;//Email
    private String phone;//联系电话
    private String password;//密码
    private String avatar;//头像
    private int type;//用户类型
    private String salt;//加盐(增加安全性)
    private boolean applyTeacher;//教师审核
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;//创建时间
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;//更新时间
    @OneToMany(mappedBy = "teacher")
    private List<Course> courses=new ArrayList<>();
    @ManyToMany(mappedBy = "students")
    private List<Course> enrolledCourses=new ArrayList<>();
    @OneToMany(mappedBy = "student")
    private List<Result> results=new ArrayList<>();
    @OneToMany(mappedBy = "student")
    private List<Applicant> applicants=new ArrayList<>();

    public User() {
        createTime=new Date();
        updateTime=createTime;
    }
    @Override
    public boolean equals(Object o){
        if(this==o)
            return true;
        if(o==null || getClass()!=o.getClass())
            return false;
        User user=(User) o;
        return id.equals(o);
    }
    @Override
    public int hashCode(){
        return Objects.hash(id);
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public boolean isApplyTeacher() {
        return applyTeacher;
    }

    public void setApplyTeacher(boolean applyTeacher) {
        this.applyTeacher = applyTeacher;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    @JsonBackReference
    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }
    @JsonBackReference
    public List<Course> getEnrolledCourses() {
        return enrolledCourses;
    }

    public void setEnrolledCourses(List<Course> enrolledCourses) {
        this.enrolledCourses = enrolledCourses;
    }
    @JsonBackReference
    public List<Result> getResults() {
        return results;
    }

    public void setResults(List<Result> results) {
        this.results = results;
    }
    @JsonBackReference
    public List<Applicant> getApplicants() {
        return applicants;
    }

    public void setApplicants(List<Applicant> applicants) {
        this.applicants = applicants;
    }
}
